Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deck: Assigned unique id to each card. #14

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

sethdivyansh
Copy link
Contributor

@sethdivyansh sethdivyansh commented May 28, 2024

  • Created an ID in the format card-type-color-value.
  • Added a sameCardCount array to uniquely identify cards of the same type and color.
  • Generated a unique ID using the format card-type-color-value-sameCardCount[id].

Fixes #4

Reason for choosing custom unique id instead of UUID etc

  1. Custom unique id contains meaningful information about the card that may help in future debuging. For example: card-Special-Red-skip-2 immediately conveys that the card is a red "skip" card and it is the second one of its kind.
  2. Generating custom id is computationally cheaper and simpler compared to generating a UUID.
  3. IDs like card-Special-Red-skip-2 are human-readable, making it easier for developers and testers to trace issues, verify game logic, and understand game states during testing and development. UUIDs, being long and non-descriptive, lack this readability.
Self-review checklist
  • Self reviewed the changes for clarity and maintainability (variable names, code reuse, readability, etc.).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.
  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

@@ -60,7 +60,16 @@ export default function getShuffledCardDeck() {
*/
function makeCard(type, color, value) {
//todo: Implement unique identification of cards by assigning an id to each card
return { type, color, value };
let card_num = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The card_num array will be lost when the function returns. We'd need to persist the array data across multiple function calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I realized my mistake later. I have corrected it; please review the updated version.

@kuv2707
Copy link
Collaborator

kuv2707 commented May 30, 2024

@sethdivyansh Please rebase your branch against upstream/main and resolve the merge conflicts.
You'd also have to deal with types now that this module is converted to TS.

I'l merge it then.

@sethdivyansh
Copy link
Contributor Author

@kuv2707 I have resolved all the conflicts. Please review the PR and merge it.

@@ -57,7 +58,13 @@ export default function getShuffledCardDeck(): Array<UNOCard> {
*/
function makeCard(type: CardType, color: CardColor, value: CardValue): UNOCard {
//todo: Implement unique identification of cards by assigning an id to each card
return { type, color, value, id: undefined };
let id = `card-${type}-${color}-${value}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer const for variables which do not change. Eslint should have given an error.

if (!sameCardCount[id]) sameCardCount[id] = 0;
sameCardCount[id]++; // increment the count of same cards to assign unique id

let uid = `${id}-${sameCardCount[id]}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@sethdivyansh sethdivyansh changed the title deck: Implement unique identification of cards by assigning an id to each card deck: Assigned unique id to each card. May 30, 2024
@sethdivyansh sethdivyansh requested a review from kuv2707 May 30, 2024 18:05
@sethdivyansh
Copy link
Contributor Author

@kuv2707 I have made all the changes.

@kuv2707
Copy link
Collaborator

kuv2707 commented May 31, 2024

@sethdivyansh Please add the "Fixes" clause in the commit message.

@sethdivyansh
Copy link
Contributor Author

sethdivyansh commented May 31, 2024

@kuv2707 Done

@sethdivyansh sethdivyansh reopened this May 31, 2024
@kuv2707 kuv2707 mentioned this pull request May 31, 2024
@kuv2707
Copy link
Collaborator

kuv2707 commented May 31, 2024

@sethdivyansh Please add the motivation to use a custom-generated ID instead of approaches like uuid etc in the PR description.
There had been some discussion regarding it in the issue page.

This PR is ready to be merged. Will do it once the event begins officially.

@sethdivyansh
Copy link
Contributor Author

@kuv2707 @shivansh-bhatnagar18 I have mentioned the reasons for choosing custom IDs. If you feel using UUIDs is a better approach, please let me know, and I will make the desired changes accordingly.

@kuv2707
Copy link
Collaborator

kuv2707 commented May 31, 2024

No, this approach is fine. I just wanted you to mention the reasoning in the PR description for future reference.

@@ -57,7 +58,13 @@ export default function getShuffledCardDeck(): Array<UNOCard> {
*/
function makeCard(type: CardType, color: CardColor, value: CardValue): UNOCard {
//todo: Implement unique identification of cards by assigning an id to each card
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sethdivyansh Remove this todo comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the comment.

- Created an ID in the format `card-type-color-value`.
- Added a `sameCardCount` array to uniquely identify cards of the same type and color.
- Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`.

Fixes shivansh-bhatnagar18#4
@kuv2707 kuv2707 merged commit f05595c into shivansh-bhatnagar18:master Jun 1, 2024
5 of 6 checks passed
@kuv2707
Copy link
Collaborator

kuv2707 commented Jun 1, 2024

Merged, thanks @sethdivyansh !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to uniquely identify cards
2 participants